Fix TilemapGPULayer when spacing != margin#7339
Open
moufmouf wants to merge 1 commit into
Open
Conversation
The stride between tiles in a tileset image is tileSize + spacing, but the shader used tileSize + margin (.zz instead of .ww). Margin is the one-off border around the sheet and is already added by getFrameCorner(), so it was counted twice while spacing was never counted at all. On any tileset where margin != spacing the sampled frame drifts by (spacing - margin) * index: correct at index 0 and progressively wrong further down the sheet, eventually rendering unrelated tiles. This matches the CPU path in Tileset.updateTileData, which strides by tileWidth + tileSpacing from an origin of tileMargin. Regenerates the bundled vert shader. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 17, 2026
moufmouf
added a commit
to workadventure/workadventure
that referenced
this pull request
Jul 17, 2026
This commit adds a patch that fixes this Phaser issue: phaserjs/phaser#7339
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR (delete as applicable)
The bug
TilemapGPULayer.vertcomputes the per-tile stride astileSize + margininstead oftileSize + spacing:SubmitterTilemapGPULayerpacks that uniform as(tileWidth, tileHeight, tileMargin, tileSpacing), so.zis margin and.wisspacing.
The stride from one tile to the next in a tileset image is
tileSize + spacing.Margin is only the one-off border around the whole sheet, and
getFrameCorner()already adds it separately (
TilemapGPULayer.frag, where the.zzis correct). Somargin was counted twice — once as the border and again on every step — while spacing
was never counted at all.
The sampled frame therefore drifts by
(spacing - margin) * index: exact at index 0and progressively wrong further down the sheet, eventually sampling entirely unrelated
tiles. Tilesets where
margin == spacingare unaffected, which is why this wentunnoticed.
The CPU path is correct, so canvas and WebGL disagree on the same map —
Tileset.updateTileData()strides bytileWidth + tileSpacingfrom an origin oftileMargin.The fix
Verification
A new example covering
margin != spacing, since no existing one does: phaserjs/examples#410Before the fix:
After the fix: